using System;
using System.Web;
using System.Web.Services.Protocols;
using System.Text;
using sb.core;

namespace sb.core.WS {
    public class WSHandler : BaseHttpHandler {
        public override void ProcessRequest(HttpContext context) {
            context.Response.ContentType = "text/javascript";

            string services = context.Request.QueryString["Services"];
            StringBuilder all = new StringBuilder();

            if (!String.IsNullOrEmpty(services)) {
                string[] servicesList = services.Split(',');

                WebServiceRestScriptFormatter rest = new WebServiceRestScriptFormatter();
                foreach (string service in servicesList) {
                    string contents = rest.GetProxyString(service);
                    all.Append("/* " + service + " */" + contents + Environment.NewLine + Environment.NewLine);
                }
                context.Response.Write(all.ToString());
            }
        }
    }
}